#ifndef SERIALPORT_H
#define SERIALPORT_H

#include <iostream>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <fstream>
#include <stdio.h>
using namespace std;

#include "Tool.h"

#define BuffLen 64

#define ComConfigur "../InitFile/ComConfigur"

class CSerialPort
{
public:
    static CSerialPort * GetInstance();
    bool Init();
    int Run(const string & Command, string & Data);
    void Cleanup();

private:
    CSerialPort();
    ~CSerialPort();
    static CSerialPort * SerialPort;

    bool ConnectSerialPort(char * COM, int Speed,int DataBits, int StopBit, char Parity);
    bool SendCommandToSerial(unsigned char * Command);
    int RecvDataFromSerial(char ** Data);
    void CloseSerialPort();

private:
    CTool * Tool;
    unsigned char SendBuff[BuffLen];
    unsigned char RecvBuff[BuffLen];
    int m_DatLen, Comfd, Speed, DataBits, StopBit;
    char Com[15];
    char Parity;

};

#endif // SERIALPORT_H
